package com.example.administrator.testdagger.tview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * com.example.administrator.testdagger.tview
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/27 9:40
 * @see com.example.administrator.testdagger.tview
 */
public class CustomTimeLineView extends View {
    public CustomTimeLineView(Context context) {
        this(context, null);
    }

    public CustomTimeLineView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomTimeLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public static final int NORMAL_COLOR = Color.GRAY;
    public static final int SELECT_COLOR = Color.GREEN;

    Paint mGrayPaint;
    Paint mBgPaint;
    Paint mLinePaint;
    int mCircleRadius = 20;


    private void init() {
        mGrayPaint = new Paint();
        mBgPaint = new Paint();
        mLinePaint = new Paint();

        mGrayPaint.setColor(NORMAL_COLOR);
        mBgPaint.setColor(Color.LTGRAY);
        mLinePaint.setColor(NORMAL_COLOR);

        mGrayPaint.setAntiAlias(true);
        mBgPaint.setAntiAlias(true);
        mLinePaint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight();
        int width = getWidth();

        canvas.drawRect(0, 0, width, height, mBgPaint);

        canvas.drawCircle(50, height / 2 - mCircleRadius, mCircleRadius, mGrayPaint);
        canvas.drawCircle(width / 2 - mCircleRadius, height / 2 - mCircleRadius,
                mCircleRadius, mGrayPaint);
        canvas.drawCircle(width - 50, height / 2 - mCircleRadius, mCircleRadius, mGrayPaint);

        canvas.drawLine(50 + mCircleRadius, height / 2 - mCircleRadius, width / 2, height / 2
                - mCircleRadius, mLinePaint);
    }
}
